home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / IEditor / Expanders / BackFill / funcs.c next >
Encoding:
C/C++ Source or Header  |  1997-06-17  |  8.3 KB  |  344 lines

  1. /// Includes
  2. #define INTUI_V36_NAMES_ONLY
  3.  
  4. #include <exec/nodes.h>                 // exec
  5. #include <exec/lists.h>
  6. #include <exec/memory.h>
  7. #include <exec/types.h>
  8. #include <dos/dos.h>                    // dos
  9. #include <intuition/intuition.h>        // intuition
  10. #include <intuition/gadgetclass.h>
  11. #include <graphics/text.h>              // graphics
  12. #include <graphics/gfxmacros.h>
  13. #include <libraries/gadtools.h>         // libraries
  14. #include <clib/exec_protos.h>           // protos
  15. #include <clib/dos_protos.h>
  16. #include <clib/intuition_protos.h>
  17. #include <clib/graphics_protos.h>
  18. #include <pragmas/exec_pragmas.h>       // pragmas
  19. #include <pragmas/dos_pragmas.h>
  20. #include <pragmas/intuition_pragmas.h>
  21. #include <pragmas/graphics_pragmas.h>
  22.  
  23.  
  24. #include <stdarg.h>
  25. #include <string.h>
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <ctype.h>
  29.  
  30. #include "DEV_IE:Expanders/defs.h"
  31. ///
  32. /// Prototypes
  33. /* we use the minimal version of the ObjectInfo */
  34. struct BFInfo {
  35.     struct Node Node;
  36.     UWORD       Kind;
  37.     UBYTE       Flags;
  38. };
  39. ///
  40.  
  41.  
  42.  
  43. /*  Starting function           */
  44. /// IEX_Mount
  45. __geta4 ULONG IEX_Mount( __A0 struct IE_Data *IE )
  46. {
  47.     BPTR                    DescFile;
  48.     struct FileInfoBlock   *fib;
  49.     ULONG                   ret = IEX_ERROR_NO_DESC_FILE;
  50.     static UBYTE            FileName[] = "PROGDIR:Expanders/BackFill.desc";
  51.  
  52.     Forbid();   /* we're going to write to a GLOBAL variable */
  53.  
  54.     if( Desc ) {            /* already mounted? */
  55.     Permit();
  56.     return( IEX_OK );
  57.     }
  58.  
  59.     LibBase->Kind      = IEX_OBJECT_KIND;
  60.  
  61.     LibBase->Resizable = FALSE;
  62.     LibBase->Movable   = FALSE;
  63.     LibBase->HasItems  = FALSE;
  64.     LibBase->UseFonts  = FALSE;
  65.  
  66.     LibBase->Node.ln_Name = "BACK FILL";
  67.  
  68.     Permit();
  69.  
  70.     if( fib = AllocDosObject( DOS_FIB, NULL )) {
  71.     if( DescFile = Lock( FileName, ACCESS_READ )) {
  72.  
  73.         Examine( DescFile, fib );
  74.         UnLock( DescFile );
  75.  
  76.         if( Desc = AllocVec( fib->fib_Size, 0L )) {
  77.         if( DescFile = Open( FileName, MODE_OLDFILE )) {
  78.             STRPTR pri;
  79.  
  80.             Read( DescFile, Desc, fib->fib_Size );
  81.             Close( DescFile );
  82.  
  83.             ( *IE->IEXFun->SplitLines )( Desc ); // VERY important!
  84.  
  85.             pri = ( *IE->IEXFun->GetFirstLine )( Desc, "RENDPRI" );
  86.  
  87.             if( pri )
  88.             LibBase->Node.ln_Pri = atoi( pri );
  89.             else
  90.             LibBase->Node.ln_Pri = 0;
  91.  
  92.             ret = IEX_OK;
  93.  
  94.         } else {
  95.             FreeVec( Desc );
  96.             Desc = NULL;
  97.         }
  98.         }
  99.  
  100.     }
  101.  
  102.     FreeDosObject( DOS_FIB, fib );
  103.     }
  104.  
  105.     return( ret );
  106. }
  107. ///
  108.  
  109.  
  110. /*  Edit functions              */
  111. /// IEX_Add
  112. __geta4 BOOL IEX_Add( __D0 UWORD ID, __A0 struct IE_Data *IE, __D1 WORD x, __D2 WORD y, __D3 UWORD width, __D4 UWORD height )
  113. {
  114.     struct BFInfo  *bf;
  115.     BOOL            ret = FALSE;
  116.  
  117.     /* we're a /toggle/ object ;-) */
  118.     bf = IE->win_info->wi_Gadgets.mlh_Head;
  119.     while(( bf->Node.ln_Succ ) && ( bf->Kind != ID ))
  120.     bf = bf->Node.ln_Succ;
  121.  
  122.     if( bf->Node.ln_Succ ) {
  123.     IE->win_info->wi_NumObjects -= 1;
  124.  
  125.     Remove(( struct Node * )bf );
  126.     FreeMem( bf, sizeof( struct BFInfo ));
  127.  
  128.     return( TRUE );
  129.     }
  130.  
  131.     if( bf = AllocMem( sizeof( struct BFInfo ), MEMF_CLEAR )) {
  132.  
  133.     bf->Kind   = ID;       /* DON'T FORGET!!! */
  134.  
  135.     /* add our object to the list */
  136.     AddTail((struct List *)&IE->win_info->wi_Gadgets, (struct Node *)bf );
  137.  
  138.     IE->win_info->wi_NumObjects += 1;
  139.  
  140.     ret = TRUE;
  141.     }
  142.  
  143.     return( ret );
  144. }
  145. ///
  146. /// IEX_Remove
  147. __geta4 void IEX_Remove( __D0 UWORD ID, __A0 struct IE_Data *IE )
  148. {
  149.     struct BFInfo  *bf;
  150.  
  151.     for( bf = IE->win_info->wi_Gadgets.mlh_Head; bf->Node.ln_Succ; bf = bf->Node.ln_Succ )
  152.     if(( bf->Kind == ID ) && ( bf->Flags & G_ATTIVO )) {
  153.         struct BFInfo *bf2 = bf->Node.ln_Pred;
  154.         Remove(( struct Node * )bf );
  155.         FreeMem( bf, sizeof( struct BFInfo ));
  156.         bf = bf2;
  157.     }
  158. }
  159. ///
  160. /// IEX_Edit
  161. __geta4 BOOL IEX_Edit( __D0 UWORD ID, __A0 struct IE_Data *IE )
  162. {
  163.     return( FALSE );
  164. }
  165. ///
  166. /// IEX_Copy
  167. __geta4 BOOL IEX_Copy( __D0 UWORD ID, __A0 struct IE_Data *IE, __D1 WORD offx, __D2 WORD offy )
  168. {
  169.     return( TRUE );
  170. }
  171. ///
  172. /// IEX_Make
  173. __geta4 struct Gadget *IEX_Make( __D0 UWORD ID, __A0 struct IE_Data *IE, __A1 struct Gadget *glist )
  174. {
  175.     /*  We don't need to make anything  */
  176.     return( glist );
  177. }
  178. ///
  179. /// IEX_Free
  180. __geta4 void IEX_Free( __D0 UWORD ID, __A0 struct IE_Data *IE )
  181. {
  182.     /*  We've got nothing to free when the window is closed  */
  183. }
  184. ///
  185. /// IEX_Refresh
  186. __geta4 void IEX_Refresh( __D0 UWORD ID, __A0 struct IE_Data *IE )
  187. {
  188.     struct BFInfo *bf;
  189.  
  190.     for( bf = IE->win_info->wi_Gadgets.mlh_Head; bf->Node.ln_Succ; bf = bf->Node.ln_Succ ) {
  191.     /*  always check the Kind  */
  192.     if( bf->Kind == ID ) {
  193.         struct DrawInfo *dri;
  194.         static UWORD Pattern[2] = { 0xAAAA, 0x5555 };
  195.  
  196.         if( dri = GetScreenDrawInfo( IE->ScreenData->Screen )) {
  197.         WORD    x1, y1, x2, y2;
  198.  
  199.         SetAPen( IE->win_info->wi_winptr->RPort, dri->dri_Pens[ SHINEPEN ]);
  200.         SetAfPt( IE->win_info->wi_winptr->RPort, &Pattern[0], 1 );
  201.  
  202.         x1 = IE->win_info->wi_winptr->BorderLeft;
  203.         y1 = IE->win_info->wi_winptr->BorderTop;
  204.         x2 = IE->win_info->wi_winptr->Width - IE->win_info->wi_winptr->BorderRight - 1;
  205.         y2 = IE->win_info->wi_winptr->Height - IE->win_info->wi_winptr->BorderBottom - 1;
  206.  
  207.         if(( x2 >= x1 ) && ( y2 >= y1 ))
  208.             RectFill( IE->win_info->wi_winptr->RPort, x1, y1, x2, y2 );
  209.  
  210.         SetAfPt( IE->win_info->wi_winptr->RPort, NULL, 0 );
  211.  
  212.         FreeScreenDrawInfo( IE->ScreenData->Screen, dri );
  213.         }
  214.  
  215.         return; /* there's just one BackFill a window...  */
  216.     }
  217.     }
  218. }
  219. ///
  220.  
  221.  
  222. /*  I/O Functions               */
  223. /// IEX_Save
  224. __geta4 void IEX_Save( __D0 UWORD ID, __A0 struct IE_Data *IE, __D1 BPTR File )
  225. {
  226. }
  227. ///
  228. /// IEX_Load
  229. __geta4 BOOL IEX_Load( __D0 UWORD ID, __A0 struct IE_Data *IE, __D1 BPTR File, __D2 UWORD Num )
  230. {
  231.     struct BFInfo   *bf;
  232.  
  233.     if( bf = AllocMem( sizeof( struct BFInfo ), MEMF_CLEAR )) {
  234.  
  235.     bf->Kind = ID;  /* VERY important!!! */
  236.  
  237.     AddTail(( struct List * )&IE->win_info->wi_Gadgets, ( struct Node * )bf );
  238.  
  239.     } else
  240.     return( FALSE );
  241.  
  242.     return( TRUE );
  243. }
  244. ///
  245.  
  246.  
  247. /*  Source related functions    */
  248. /// IEX_StartSrcGen
  249. __geta4 STRPTR IEX_StartSrcGen( __D0 UWORD ID, __A0 struct IE_Data *IE )
  250. {
  251.     struct WindowInfo *wnd;
  252.     struct BFInfo     *bf;
  253.  
  254.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  255.     if( wnd->wi_NumObjects ) {
  256.         for( bf = wnd->wi_Gadgets.mlh_Head; bf->Node.ln_Succ; bf = bf->Node.ln_Succ ) {
  257.         if( bf->Kind == ID ) {
  258.             wnd->wi_NeedRender = TRUE;
  259.             break;
  260.         }
  261.         }
  262.     }
  263.     }
  264.  
  265.     return(( *IE->IEXFun->GetFirstLine )( Desc, "SUPPORT" ));
  266. }
  267. ///
  268. /// IEX_WriteGlobals
  269. __geta4 void IEX_WriteGlobals( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  270. {
  271.     UBYTE   *String;
  272.  
  273.     if( String = ( *IE->IEXFun->GetFirstLine )( Desc, "GLOBAL" ))
  274.     FPuts( Files->Std, String );
  275. }
  276. ///
  277. /// IEX_WriteSetup
  278. __geta4 void IEX_WriteSetup( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  279. {
  280. }
  281. ///
  282. /// IEX_WriteCloseDown
  283. __geta4 void IEX_WriteCloseDown( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  284. {
  285. }
  286. ///
  287. /// IEX_WriteHeaders
  288. __geta4 void IEX_WriteHeaders( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  289. {
  290.     STRPTR string;
  291.  
  292.     if( string = ( *IE->IEXFun->GetFirstLine )( Desc, "HEADER" ))
  293.     FPuts( Files->XDef, string );
  294.  
  295.     if( string = ( *IE->IEXFun->GetFirstLine )( Desc, "INCLUDE" ))
  296.     FPuts( Files->Std, string );
  297. }
  298. ///
  299. /// IEX_WriteRender
  300. __geta4 void IEX_WriteRender( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  301. {
  302.     struct Descriptor   Dsc[] = {
  303.     { 'w', IE->win_info->wi_Label },
  304.     { 0, NULL }
  305.     };
  306.     struct BFInfo   *bf;
  307.     STRPTR           String;
  308.  
  309.     if(( IE->win_info->wi_NumObjects ) && ( String = ( *IE->IEXFun->GetFirstLine )( Desc, "RENDER" ))) {
  310.     for( bf = IE->win_info->wi_Gadgets.mlh_Head; bf->Node.ln_Succ; bf = bf->Node.ln_Succ ) {
  311.         if( bf->Kind == ID ) {
  312.         ( *IE->IEXFun->WriteFormatted )( Files->Std, String, &Dsc[0] );
  313.         }
  314.     }
  315.     }
  316. }
  317. ///
  318. /// IEX_GetIDCMP
  319. __geta4 ULONG IEX_GetIDCMP( __D0 UWORD ID, __D1 ULONG idcmp, __A0 struct IE_Data *IE )
  320. {
  321.     return( idcmp );
  322. }
  323. ///
  324. /// IEX_WriteData
  325. __geta4 void IEX_WriteData( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  326. {
  327. }
  328. ///
  329. /// IEX_WriteChipData
  330. __geta4 void IEX_WriteChipData( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  331. {
  332. }
  333. ///
  334. /// IEX_WriteOpenWnd
  335. __geta4 void IEX_WriteOpenWnd( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  336. {
  337. }
  338. ///
  339. /// IEX_WriteCloseWnd
  340. __geta4 void IEX_WriteCloseWnd( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  341. {
  342. }
  343. ///
  344.